package com.ease.platform.authorization.service.impl;

import com.ease.common.exception.NestedException;
import com.ease.common.util.Detect;
import com.ease.platform.authorization.service.AnonymousAuthorizationService;
import com.ease.platform.authorization.service.AuthorizationService;
import com.ease.platform.usercontext.vo.UserContext;

/**
 * 
 * @author nathanleewei
 * 
 */
public abstract class AbstractAuthorizationServiceImpl extends Detect implements AuthorizationService {

	private UserContext anonymousUserContext;

	private static final String ANONYMOUS = "anonymous";

	protected void throwUnaccessibleException() {
		throw new RuntimeException("unaccessible function, please ");
	}

	// TODO to be replaced by UserContext.getUserContext()
	// override
	public UserContext getAnonymousUserContext() {
		if (this instanceof AnonymousAuthorizationService) {
			if (null == anonymousUserContext) {
				anonymousUserContext = new UserContext();
				anonymousUserContext.setOperator(ANONYMOUS);
				// anonymousUserContext.setResult(UserContext.Result.SUCCESS);
			}
			return anonymousUserContext;
		}
		throw new NestedException("getAnonymousUserContext invalid!");
	}
}
